<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //简单应用发布订阅模式
    class Notify {
        constructor() {
            this.subscribers = []
        }

        //将handler 排入数组
        add(handler) {
            // console.log(handler, 'S')
            this.subscribers.push(handler)

        }

        //执行所有的handler
        emit() {
            this.subscribers.forEach(subscriber => subscriber())
        }
    }

    //应用
    let notify = new Notify()
    notify.add(() => {
        console.log('emit here111')
    })
    notify.emit()
</script>
</body>
</html>